home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group96b.txt
/
000055_icon-group-sender _Fri Nov 8 22:00:52 1996.msg
< prev
next >
Wrap
Internet Message Format
|
1997-01-02
|
3KB
Received: by cheltenham.cs.arizona.edu; Mon, 11 Nov 1996 10:00:16 MST
To: icon-group@cs.arizona.edu
Date: 8 Nov 1996 22:00:52 -0700
From: dps@azstarnet.com (dave schaumann)
Message-Id: <561364$hcf@web.azstarnet.com>
Organization: Starnet, Tucson, Az.
Sender: icon-group-request@cs.arizona.edu
References: <55qhto$66r@netty.york.ac.uk>
Subject: Re: sets and structures
Errors-To: icon-group-errors@cs.arizona.edu
In article <55qhto$66r@netty.york.ac.uk>,
stephen parker <stephen@lila.york.ac.uk> wrote:
>i'm reading ``An Overview of the Icon Programming Language; Version 8''
>(Griswold). the section on sets says: ``insert(S, x) has no effect if x
>is already in S''.
This is absolutely true. What you're not understanding is what
the phrase 'x is already in S' means.
There are two ways that values can be implemented: mutable or
immutable.
If a type is immutable, values of that type are unique and cannot be
changed. Any operation that changes the value creates a new instance
of that type (as opposed to merely changing the old value in some way).
Integers are an example of an immutable type.
Conversely, if a type is mutable, values are not unique, and operations
on the value change the value.
This will probably be cleared up by an example. Consider the following
pseudo code:
x := some_value;
y := x;
x := some operation on x
if (y is still the same value as x)
then the value of x (and y) is of mutable type
else
the values of x (and y) are of immutable type
thus,
x := 3;
y := x;
x := x + 1;
# x ~= y here, so integers are of immutable type
# Each value of an immutable type is unique, so whenever you
# name it, you get the same value. Each integer value 3 is
# the same as any other integer value 3.
x := []
y := x
put(x, 3)
# x is still the same list as y here, so lists are mutable.
# Values in a mutable type are *not* unique, and typically
# each time you name a value in a mutable type, you get a new
# and unique value, even if the name is the same. Hence,
# in the following code
x := []
y := []
# x and y have different values, even though they were
# created from the same name. If this code is executed
# in a loop, x and y will be assigned with two new values,
# each different from all the other values. Thus, it doesn't
# matter if you write
s := set();
insert(s, [])
insert(s, [])
# or you write
s := set();
every 1 to 2 do
insert(s, [])
# both code fragments insert two different lists into the set.
>so, what's the answer if you want to form a set of non-atomic types?
>do i have to do it by hand?
Yup. I'm not aware of any data structure that makes it easy (or fast)
to deal with sets containg elements that are not easy to compare (like
lists).
>i suppose the answer is to buy the book -- i will when i have chance.
That would be an excellent idea. Icon is a very cool language, but
it does have some pitfalls you can easily fall into.
-Dave
--
No matter how much we ask after the truth, self-awareness is
often unpleasant. We do not feel kindly toward the Truthsayer.
-- Frank Herbert